<?php

namespace App\Api;

use App\Http\Controllers\Controller;
use App\Models\Slide;
use Illuminate\Http\Request;

class SlideController extends Controller
{

    public function index()
    {
        $slidees = Slide::all();
        return $slidees;
    }

    public function store(Request $request)
    {
        $request->validate([
            'title' => ['required'],
            'url' => ['required'],
        ], [
            'title.required' => '标题不能为空',
            'url.required' => '请上传图片'
        ]);
        Slide::create($request->input());
        return $this->message('添加成功');
    }


    public function show(Slide $slide)
    {
        return $slide;
    }


    public function edit(Slide $slide)
    {
        return $slide;
    }

    public function update(Request $request, Slide $slide)
    {
        $request->validate([
            'title' => ['required'],
            'url' => ['required'],
        ], [
            'title.required' => '标题不能为空',
            'url.required' => '请上传图片'
        ]);
        $slide->update($request->input());
        return $this->message('修改成功');
    }

    public function destroy(Slide $slide)
    {
        $slide->delete();
        return $this->message('删除成功');
    }
}
